<template>
	<!-- 轮播图区域 -->
	<view class="goods">
		<swiper :indicator-dots="true" :autoplay="true" :circular="true" :interval="5000" :duration="1000">
			<swiper-item v-for="item in swipers" :key="item.goods_id">
				<image :src="item.image_src"></image>
			</swiper-item>
		</swiper>
		<!-- 推荐商品区域 -->
		<view class="hot_goods">
			<view class="title">推荐商品</view>
			<goods-list @goodsItemClick="goGoodsDetail" :goods="goods"></goods-list>
			<!-- <view class="goods_list">
				<view class="goods_item" v-for="item in goods" :key="item.id">
					<image :src="item.img_url"></image>
					<view class="price">
						<text>¥{{item.sell_price}}</text>
						<text>¥{{item.market_price}}</text>
					</view>
					<view class="goods_name">
						{{item.title}}
					</view>
				</view>
			</view> -->
		</view>
	</view>
	
	
</template>

<script>
	import goodsList from "../../components/goods-list/goods-list.vue"
	export default {
		data() {
			return {
				swipers: [],
				goods:[]
			}
		},
		components:{"goods-list":goodsList},
		onLoad() {
			this.getSwipers();
			this.getHotGoods();
		
		},
		methods: {
			//获取商品列表数据
			async getSwipers() {
				const res = await this.$myRequest({
					url: '/home/swiperdata'
				})
				this.swipers = res.data.message
			},
			//获取热门商品列表数据
			async getHotGoods(){
			const res = await this.$myrequest({
					url:'/api/getgoods?pageindex=1'
				})
				this.goods = res.data.message
			},
			//导航到商品详情页
			goGoodsDetail(id){
				uni.navigateTo({
					url:'/pages/goods-detail/goods-detail?id='+id
				})
			}
		}
	}
</script>

<style lang="scss">
	.goods{
		margin-top: 5rpx;
		swiper{
			width: 750rpx;
			height: 380rpx;
			image{
				height: 100%;
				width: 100%;
			}
		}
		.hot_goods{
			background: #eee;
			overflow: hidden;
			.title{
				height: 50px;
				line-height: 50px;
				color: $shop-color;
				text-align: center;
				letter-spacing: 20px;
				background: #fff;
				margin: 8rpx;
				font-weight: 600;
			}
			.goods_list{
				padding: 0 15rpx;
				display: flex;
				flex-wrap: wrap;
				justify-content: space-between;
				.goods_item{
					background: #fff;
					width: 355rpx;
					margin: 10rpx 0;
					padding: 15rpx;
					box-sizing: border-box;
					image{
						width: 80%;
						height: 150px;
						display: block;
						margin: auto;
					}
				}
				.price{
					color: $shop-color;
					font-size: 36rpx;
					margin: 20rpx 0 5rpx 0;
					text:nth-child(2){
						color: #ccc;
						font-size: 28rpx;
						margin-left: 18rpx;
						text-decoration: line-through;
					}
				}
				.goods_name{
					font-size: 28rpx;
					line-height: 50rpx;
					padding-bottom: 15rpx;
					padding-top: 10rpx;
				}
			}
		}
	}

</style>
